package test.com.hezuti;


import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * This is an automatically generated DAO class which should not be edited.
 */
public class SpringConfigureHelper {

	private SpringConfigureHelper() {
	}

	// query name references
	private static SpringConfigureHelper instance = null;

	private static ApplicationContext ctx = null;

	private static String DEFAULT_SPRING_CONFIGURE_FILE_NAME = "springApplicationContext.xml";

	/**
	 * Return a singleton of the DAO
	 */
	public static SpringConfigureHelper getInstance() {
		if (null == instance)
			instance = new SpringConfigureHelper();
		return instance;
	}

	/**
	 * Configure ApplicationContext.
	 */
	public static void configure() {
		ctx = new ClassPathXmlApplicationContext(DEFAULT_SPRING_CONFIGURE_FILE_NAME);
	}

	/**
	 * Configure the ApplicationContext. If the configFileName is null, use the
	 * DEFAULT_SPRING_CONFIGURE_FILE_NAME.
	 */
	public static void configure(final String configFileName) {
		if (null == configFileName) {
			ctx = new ClassPathXmlApplicationContext(DEFAULT_SPRING_CONFIGURE_FILE_NAME);
		} else {
			ctx = new ClassPathXmlApplicationContext(configFileName);
		}
	}

	/**
	 * Configure the ApplicationContext. If the configFileName is null, use the
	 * DEFAULT_SPRING_CONFIGURE_FILE_NAME.
	 */
	public static void configure(final String configFileNames[]) {
		if (null == configFileNames) {
			ctx = new ClassPathXmlApplicationContext(DEFAULT_SPRING_CONFIGURE_FILE_NAME);
		} else {
			ctx = new ClassPathXmlApplicationContext(configFileNames);
		}
	}

	public static Object getBean(final String beanName) {
		if (null == ctx) {
			SpringConfigureHelper.configure();
		}
		if (null == ctx) {
			return null;
		}
		return ctx.getBean(beanName);
	}

}